package org.chmodke.proxy.socks.config;

import org.chmodke.proxy.socks.util.C;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;

/**
 * @author kehao
 * @version 1.0
 * @date 2019/3/15 10:28
 */
public class ServerConfig {
    public static final int SERVER_PORT;
    public static final boolean OPEN_SOCK_4;
    public static final boolean OPEN_SOCK_5;
    public static final String USER;
    public static final String PWD;
    private static final Logger logger = LoggerFactory.getLogger(ServerConfig.class);

    static {
        Properties server = new Properties();
        try {
            File config = new File(System.getProperty("user.dir") + File.separator + "ssr.properties");
            if (config.exists()) {
                server.load(new FileInputStream(config));
            } else {
                server.load(ServerConfig.class.getClassLoader().getResourceAsStream("ssr.properties"));
            }
        } catch (Exception e) {
            logger.error("{}:ServerConfig.init->Exception:", C.MAIN_LOG, e);
        }
        SERVER_PORT = Integer.parseInt(server.getProperty("serverPort"));
        OPEN_SOCK_4 = Boolean.parseBoolean(server.getProperty("openSock4"));
        OPEN_SOCK_5 = Boolean.parseBoolean(server.getProperty("openSock5"));
        USER = server.getProperty("user");
        PWD = server.getProperty("pwd");
    }
}
